package com.sysu.minsysu.map;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.location.Location;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

import com.sysu.minsysu.Main;
import com.sysu.minsysu.R;
import com.sysu.minsysu.utils.Utils;


public class Maps extends Activity{
	
	GridView mGridView;
	Bitmap[] mBitmaps;
	Integer[] mBitmapRes;
	
	
	
	@Override
	public void onCreate( Bundle savedInstanceState ){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.gridmainlayout);
		mGridView = (GridView)findViewById(R.id.gridview);

		mGridView.setNumColumns(2);
		mGridView.setAdapter( new MyImageAdapter(this));
		mGridView.setOnItemClickListener(new MyOnItemClickListener());
		
		
	}
	
	@Override
	public boolean onKeyDown( int keyCode, KeyEvent event){
		if( keyCode==KeyEvent.KEYCODE_BACK)
			return false;
		else return super.onKeyDown(keyCode, event);
	}
	
	private class MyImageAdapter extends BaseAdapter{
		
		Activity mActivity;
		public MyImageAdapter( Activity activity) {
			mActivity = activity;
			LayoutInflater inflater = mActivity.getLayoutInflater();
			
			views = new View[2];
			for( int i=0; i<2; i++ ){
				views[i] = inflater.inflate(R.layout.view_appmain, null);
				((ImageView)(views[i].findViewById(R.id.imageView))).setImageResource(pics[i]);
				((TextView)(views[i].findViewById(R.id.textView))).setText(texts[i]);
			}
		}

		@Override
		public int getCount() {
			return 2;
		}

		@Override
		public Object getItem(int arg0) {
			return arg0;
		}

		@Override
		public long getItemId(int arg0) {
			return arg0;
		}

		@Override
		public View getView(int arg0, View arg1, ViewGroup arg2) {
			return views[arg0];
		}
		
		private View[] views;
		
		private int[] pics = new int[]{
				R.drawable.tuguanxiaojing_xiaoquditu,
				R.drawable.tuguanxiaojing_tushuozhongda,

		};
		
		private String[] texts = new String[]{
				"东校区", "南校区",
		};
	}
	
	private class MyOnItemClickListener implements OnItemClickListener{

		@Override
		public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			
			Bundle bundle=null;
			Intent intent=null;
			double[] center=null;
			ArrayList<PlaceInfo> placeInfos;
			switch ( arg2) {
			case 0:
				center = new double[]{ 23.0666, 113.3920 };
				placeInfos = MapInfo.getEastMapInfo();
				break;

			default:
				Toast.makeText(Maps.this, "功能还在完善中……敬请期待", Toast.LENGTH_SHORT).show();
				return;
			}
			bundle = Utils.getBundleToStartMap( placeInfos, center);
			intent = new Intent(Maps.this, ShowPositionsOnMap.class);
			intent.putExtras(bundle);
			startActivity(intent);
		}
		
	}
}
